import java.awt.Graphics;
import java.awt.Image;
import java.util.Vector;

public class TargetSprite extends Sprite {

	protected Gameloop gameloop;
	protected Image imageTarget;
	protected Image imagePopUp;

	private Vector<BeeSprite> list = new Vector<BeeSprite>();

	protected int points;
	protected int beeScore;
	protected int ladyScore;
	protected int score;

	protected int wait = 40;

	public int getTotalScore() {
		return points;
	}

	public int getBeeScore() {
		return beeScore;
	}

	public int getLadyScore() {
		return ladyScore;
	}

	public TargetSprite(Gameloop gl) {
		super();

		gameloop = gl;

		imageTarget = ImageLoader.get().read("/Images/Target.png");
		imagePopUp = ImageLoader.get().read("/Images/Design.png");

		width = 50;
		height = 50;
	}

	private int checkHit() {

		list.addAll(gameloop.getBees());
		list.addAll(gameloop.getDrunkBees());
		list.addAll(gameloop.getLadybugs());
		list.addAll(gameloop.getDragonflies());

		score = 0;
		beeScore = 0;
		ladyScore = 0;

		if (gameloop.getIsTarget()) {
			for (BeeSprite sp : list) {
				if (!sp.getIsHit()) {
					boolean ishit = Util.pointInsideRectangle(x, y, sp.getX(),
							sp.getY(), sp.getWidth(), sp.getHeight());
					if (ishit) {
						sp.setIsHit(true);
						score += sp.getValue();
						if (sp instanceof LadybugSprite) {
							wait = 0;
							ladyScore++;
						} else {
							beeScore++;
						}
					}
				}
			}
		}
		return score;
	}

	public void update() {

		x = gameloop.getMouseX();
		y = gameloop.getMouseY();

		points = checkHit();
	}

	public void draw(Graphics g) {

		if (wait < 40) {
			g.drawImage(imagePopUp, 325, 150, 351, 247, null);
			wait++;
		}

		g.drawImage(imageTarget, x - (width / 2), y - (height / 2), width,
				height, null);
	}
}
